from http.server import HTTPServer, BaseHTTPRequestHandler
import json
import subprocess
import os

class Resquest(BaseHTTPRequestHandler):
    def handler(self):
        print("data:", self.rfile.readline().decode())
        self.wfile.write(self.rfile.readline())

    def do_POST(self):
        print("hello webhook..")
        os.system('cd ./project/pear-admin-flask && git add . && git status  && git stash ;git stash clear;git pull')
        print("git pull finished")

if __name__ == '__main__':
    host = ('', 9002)
    server = HTTPServer(host, Resquest)
    print("Starting server, listen at: %s:%s" % host)
    server.serve_forever()
